﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data;
using System.Data.SqlClient;


namespace DAO
{
    public class BudgetDataAccess : Connection
    {
        private string _strSPGetAllName = "dbo.[procOrganizations_getall]";

        public DataTable GetAll(
        ref string sErr)
        {
            connect();
            InitSPCommand(_strSPGetAllName);
            DataTable list = new DataTable();
            try
            {
                list = executeSelectSP();
            }
            catch (Exception ex)
            {
                sErr = ex.Message;
            }
            disconnect();


            if (sErr != "") ErrorLog.SetLog(sErr);
            return list;
        }

        public decimal getTotalAmtHL(string code, ref string sErr)
        {
            decimal ret = 0;
            connect();
            string sql = @"SELECT SUM(LimitAmt) as Amount
                FROM  Budgets
                WHERE Contract =  @Contract";

            InitCommand(sql, CommandType.Text);

            AddParameter("Contract", code);


            try
            {
                ret = Convert.ToDecimal(executeScalar());
            }
            catch (Exception ex)
            {
                sErr = ex.Message;
            }
            disconnect();
            if (sErr != "") ErrorLog.SetLog(sErr);

            return ret;
        }

        public decimal getTotalAmtHV(string code, ref string sErr)
        {
            decimal ret = 0;
            connect();
            string sql = @"SELECT SUM(LimitAmt) as Amount
                FROM  Budgets1
                WHERE Contract =  @Contract";

            InitCommand(sql, CommandType.Text);

            AddParameter("Contract", code);


            try
            {
                ret = Convert.ToDecimal(executeScalar());
            }
            catch (Exception ex)
            {
                sErr = ex.Message;
            }
            disconnect();
            if (sErr != "") ErrorLog.SetLog(sErr);

            return ret;
        }
    }
}
